'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.ue4Init = ue4Init;
exports.getUe4 = getUe4;
exports.default = void 0;

function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object);
  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object);
    if (enumerableOnly)
      symbols = symbols.filter(function(sym) {
        return Object.getOwnPropertyDescriptor(object, sym).enumerable;
      });
    keys.push.apply(keys, symbols);
  }
  return keys;
}

function _objectSpread(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = arguments[i] != null ? arguments[i] : {};
    if (i % 2) {
      ownKeys(Object(source), true).forEach(function(key) {
        _defineProperty(target, key, source[key]);
      });
    } else if (Object.getOwnPropertyDescriptors) {
      Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
      ownKeys(Object(source)).forEach(function(key) {
        Object.defineProperty(
          target,
          key,
          Object.getOwnPropertyDescriptor(source, key),
        );
      });
    }
  }
  return target;
}

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true,
    });
  } else {
    obj[key] = value;
  }
  return obj;
}

var config = {
  ep: '',
  getUe4ToWebKyes: '',
  getWebToUe4Kyes: '',
};

function ue4Init(data) {
  config = data;

  require('./ue4Init');

  ue4EventsInit();
  return getUe4();
}

function getUe4() {
  return _objectSpread(
    _objectSpread({}, config),
    {},
    {
      webToUe4: webToUe4,
    },
  );
} //事件初始化

function ue4EventsInit() {
  var _getUe = getUe4(),
    ep = _getUe.ep,
    getUe4ToWebKyes = _getUe.getUe4ToWebKyes; // 使用eq转发 ue4ToWeb 事件

  Object.keys(getUe4ToWebKyes).forEach(function(key, i) {
    ue.interface[key] = function(data) {
      return ep.emit(key, data);
    };
  }); // 使用监听  webToUe4 事件

  ep.on('webToUe4', function(webToUe4Data) {
    var type = webToUe4Data.type,
      data = webToUe4Data.data;
    window.ue4(type, data);
  });
} // 向 ue4发送事件

function webToUe4(type, data) {
  var _getUe2 = getUe4(),
    ep = _getUe2.ep,
    getUe4ToWebKyes = _getUe2.getUe4ToWebKyes;

  ep.emit('webToUe4', {
    type: type,
    data: data,
  });
}

var _default = {
  ue4Init: ue4Init,
  getUe4: getUe4,
};
exports.default = _default;
